package com.movie.utils;

import com.movie.bean.*;
import com.movie.service.MovieService;
import com.movie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author smily
 * @Description 订单转换
 * @date 2023/4/25 14:31
 */
@Component
public class TicketOrderUtil {
    @Autowired
    private MovieService movieService;

    @Autowired
    private UserService userService;

    public TicketOrder ticketOrderUtil(List<Ticket> ticketList, long expireTime) {
        Ticket ticket = ticketList.get(0);
        int amount = ticketList.size();
        int movid = ticket.getMovid();
        String number = ticket.getNumber();
        Movie movie = movieService.getMovieById(movid);
        int sessionid = ticket.getSessionid();
        Session session = movieService.getSession(sessionid);
        User user = userService.getUserByUid(ticket.getUseid());
        int total = ticket.getTprice() * amount;
        String seat = ticket.getSeat() + "";
        for (int i = 1; i < ticketList.size(); i++) seat += "," + ticketList.get(i).getSeat();
        String buyTime = ticket.getBuyTime();
        String room = session.getRoom();
        TicketOrder ticketOrder = new TicketOrder(amount, number, movie, user, session, total, 0, seat, buyTime, room,expireTime,"");
        return ticketOrder;
    }
}
